package treeset.demo03;

// 定义一个学生类，并且定义对应的成员变量
// (name , chineseScore , mathScore ,englishScore),
// 并且提供对应的get和set方法;为了方便对总分进行
public class Student implements Comparable<Student> {
    private String name;
    private String chinesecore;
    private String mathScore;
    private String englishScore;

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", chinesecore='" + chinesecore + '\'' +
                ", mathScore='" + mathScore + '\'' +
                ", englishScore='" + englishScore + '\'' +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getChinesecore() {
        return chinesecore;
    }

    public void setChinesecore(String chinesecore) {
        this.chinesecore = chinesecore;
    }

    public String getMathScore() {
        return mathScore;
    }

    public void setMathScore(String mathScore) {
        this.mathScore = mathScore;
    }

    public String getEnglishScore() {
        return englishScore;
    }

    public void setEnglishScore(String englishScore) {
        this.englishScore = englishScore;
    }

    public Student(String name, String chinesecore, String mathScore, String englishScore) {
        this.name = name;
        this.chinesecore = chinesecore;
        this.mathScore = mathScore;
        this.englishScore = englishScore;
    }

    //在学习类中在提供一个getTotalScore的方法去获取总分；
    public int getTotalScore(Student a) {
        int ch = Integer.parseInt(a.chinesecore);
        int math = Integer.parseInt(a.mathScore);
        int eng = Integer.parseInt(a.englishScore);

        return ch + math + eng;

    }


    public Student() {
    }

    @Override
    public int compareTo(Student o) {
        int ch = Integer.parseInt(this.chinesecore);
        int ch2 = Integer.parseInt(o.chinesecore);
        int math = Integer.parseInt(this.mathScore);
        int math2 = Integer.parseInt(o.mathScore);
        int eng = Integer.parseInt(this.englishScore);
        int eng2 = Integer.parseInt(o.englishScore);
        int i1 = getTotalScore(this) - getTotalScore(o);
        int i = i1 == 0 ? this.name.compareTo(o.name) : i1;
        int i2 = i == 0 ? ch - ch2 : i;
        int i3 = i2 == 0 ? math - math2 : i2;

        return i3;
    }
}
